package com.cskaoyan.mall.cart.controller.inner;

import com.cskaoyan.mall.cart.api.dto.CartInfoDTO;
import com.cskaoyan.mall.cart.client.ProductApiClient;
import com.cskaoyan.mall.cart.service.CartService;
import com.cskaoyan.mall.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author Pudding
 * @Date 2024/7/17 10:13
 */
@RestController
public class CartApiController {

    @Autowired
    ProductApiClient productApiClient;
    @Autowired
    CartService cartService;

    /**
     * 下单的时候 查询购物车中所有被选中的商品
     * @param userId
     * @return
     */
    @GetMapping("/api/cart/inner/getCartCheckedList/{userId}")
    public List<CartInfoDTO> getCartCheckedList(@PathVariable(value = "userId") String userId){

        List<CartInfoDTO> cartCheckedList = cartService.getCartCheckedList(userId);
        return cartCheckedList;
    }

    // 更新用户购物车中商品价格
    @GetMapping("/api/cart/inner/refresh/{userId}/{skuId}")
    public Result refreshCartPrice(@PathVariable(value = "userId") String userId, @PathVariable(value = "skuId") Long skuId){

        //1. 调用购物车服务更新价格
        cartService.refreshCartPrice(userId, skuId);

        return Result.ok();
    }

    //删除购物车中已经下单的商品
    @PutMapping("/api/cart/inner/delete/order/cart/{userId}")
    public Result removeCartProductsInOrder(@PathVariable("userId") String userId, @RequestBody List<Long> skuIds){

        cartService.delete(userId, skuIds);
        return Result.ok();
    }
}
